package com.zhongan.gateway;

import java.util.ArrayList;
import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.context.embedded.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

import com.zhongan.gateway.filter.PrintResFilter;
import com.zhongan.gateway.web.filter.LoginFilter;

@SpringBootApplication
@ImportResource("classpath:beanRefContext.xml")
@EnableAutoConfiguration(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
@Configuration
@EnableFeignClients
@EnableZuulProxy
@EnableCaching
@ServletComponentScan
public class TechGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(TechGatewayApplication.class, args);
    }

    @Bean
    public FilterRegistrationBean dealResFilterRegistration(PrintResFilter printResFilter) {

        FilterRegistrationBean ssoFilterRegistration = new FilterRegistrationBean();
        ssoFilterRegistration.setFilter(printResFilter);
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/gw/*");
        //        urlPatterns.add("/gry/gw/*");
        ssoFilterRegistration.setUrlPatterns(urlPatterns);

        return ssoFilterRegistration;
    }

    @Bean
    public FilterRegistrationBean loginFilterRegistration(LoginFilter loginFilter) {

        FilterRegistrationBean ssoFilterRegistration = new FilterRegistrationBean();
        ssoFilterRegistration.setFilter(loginFilter);
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        //        urlPatterns.add("/gry/gw/*");
        ssoFilterRegistration.setUrlPatterns(urlPatterns);
        //        ssoFilterRegistration.set
        return ssoFilterRegistration;
    }

}
